<template>
	<div class="addProject business-workAdd">
		<div class="addForm zll-form">
			<div style="display: flex;line-height: 40px;">
				<p style="font-size: 16px; width: 110px;">{{tabName}}</p>

				<el-select :disabled="disabled" :popper-append-to-body="!isScreenfull" v-model="addForm.taskId" placeholder="请选择计划名、规格" class="input_right" clearable filterable>
					<el-option :label="item.label" :value="item.id" v-for="(item,index) in plans" :key="index"></el-option>
				</el-select>
			</div>
			<div class="tableList" style="margin-top: 10px;">
				<table border="1">
					<tr>
						<th>直径±0.1mm</th>
						<th>长度±2mm</th>
						<th>产品重量（g）</th>
						<th>气味</th>
						<th>杂质</th>
						<th>外观</th>
						<th>壁厚≤0.02mm</th>
						<th>尖口≥45°</th>
					</tr>
					<tr class="add_Table">
						<td>
							<!--<el-input @input="addForm.zjValue=addForm.zjValue.replace(/[^0-9\.]/g,'')" v-model="addForm.zjValue" placeholder="" class="text_center" clearable-->
									  <!--:disabled="disabled"></el-input>-->
							<el-input v-model="addForm.zjValue" placeholder="" class="text_center" clearable
									  :disabled="disabled"></el-input>
						</td>
						<td>
							<!--<el-input @input="addForm.cdValue=addForm.cdValue.replace(/[^0-9\.]/g,'')" v-model="addForm.cdValue" placeholder="" class="text_center" clearable-->
									  <!--:disabled="disabled"></el-input>-->
							<el-input v-model="addForm.cdValue" placeholder="" class="text_center" clearable
									  :disabled="disabled"></el-input>
						</td>
						<td>
							<el-input @input="addForm.zlValue=addForm.zlValue.replace(/[^0-9\.]/g,'')" v-model="addForm.zlValue" placeholder="" class="text_center" clearable
									  :disabled="disabled"></el-input>
						</td>
						<td>
							<el-select :disabled="disabled" :popper-append-to-body="!isScreenfull" v-model="addForm.qwValue" placeholder="请选择气味" class="input_right" clearable >
								<el-option label="优" value="优" ></el-option>
								<el-option label="无" value="无" ></el-option>
							</el-select>
							<!--<el-input v-model="addForm.qwValue" placeholder="" class="text_center" clearable-->
									  <!--:disabled="disabled"></el-input>-->
						</td>
						<td>
							<!--<el-input v-model="addForm.zzValue" placeholder="" class="text_center" clearable-->
									  <!--:disabled="disabled"></el-input>-->
							<el-select :disabled="disabled" :popper-append-to-body="!isScreenfull" v-model="addForm.zzValue" placeholder="请选择杂志" class="input_right" clearable >
								<el-option label="优" value="优" ></el-option>
								<el-option label="无" value="无" ></el-option>
							</el-select>
						</td>
						<td>
							<el-select :disabled="disabled" :popper-append-to-body="!isScreenfull" v-model="addForm.wgValue" placeholder="请选择外观" class="input_right" clearable >
								<el-option label="优" value="优" ></el-option>
								<el-option label="无" value="无" ></el-option>
							</el-select>
							<!--<el-input v-model="addForm.wgValue" placeholder="" class="text_center" clearable-->
									  <!--:disabled="disabled"></el-input>-->
						</td>
						<td>
							<!--<el-input @input="addForm.phValue=addForm.phValue.replace(/[^0-9\.]/g,'')" v-model="addForm.phValue" placeholder="" class="text_center" clearable-->
									  <!--:disabled="disabled"></el-input>-->
							<el-input  v-model="addForm.phValue" placeholder="" class="text_center" clearable
									  :disabled="disabled"></el-input>
						</td>
						<td>
							<!--<el-input  v-model="addForm.jkValue" placeholder="" class="text_center" clearable-->
									   <!--:disabled="disabled"></el-input>-->
							<el-select :disabled="disabled" :popper-append-to-body="!isScreenfull" v-model="addForm.jkValue" placeholder="请选择尖口" class="input_right" clearable >
								<el-option label="45-60" value="45-60" ></el-option>
								<el-option label="无" value="无" ></el-option>
							</el-select>
						</td>
					</tr>
				</table>
			</div>
			<div v-if="!addForm.lineStatus ||addForm.lineStatus == '0' || addForm.lineStatus == '2'">
				<p class="zll-botton Info" style="background-color: #1890ff;width: 268px;margin-top: 20px;" @click="productMachine">开机生产</p>
			</div>
			<div v-if="addForm.lineStatus == '1'">
				<p class="zll-botton Info" style="background-color: #ff4b2d;width: 268px;margin-top: 20px;" @click="stopMachine">停机</p>
			</div>
		</div>
	</div>
</template>
<script>
	import {getStore} from "@/plugins/localStore";
	import {formatDate} from "@/plugins/formatDate";

	export default {
		props: ['editData', 'type','tabName','isScreenfull'],
		data() {
			return {
				addForm: {
					id:'',
					deviceCode:'',
					taskId:'',
					planName:'',
					gradeValue:'',
					zjValue:'',
					cdValue:'',
					zlValue:'',
					qwValue:'',
					zzValue:'',
					wgValue:'',
					phValue:'',
					jkValue:'',
					checkTime:'',
					createUserName:'',
					zjUserName:'',
					lineType:'',
					lineStatus:'',
				},

				disabled:false,

				plans:[],
			}
		},
		methods: {
			submitForm(val, type) {
				let self = this;
				self.operate();

			},

			productMachine(){
				if(!this.addForm.taskId ){
					this.$message.warning('请选择任务！');
					return;
				}
				this.operate('start');
			},

			stopMachine(){
				let self = this;
				if(!this.addForm.id ){
					this.$message.warning('数据异常，请刷新页面重试！');
					return;
				}
				let params = {id:self.addForm.id,lineStatus:'2'};
				self.$http({
					url: "/jinl/lineOther/updateLineOther",
					method: "post",
					params:params
				}).then(resp => {
					if (resp.success) {
						console.log(resp.result);
						self.$message.success('停机成功')
						self.$eventBus.$emit('updatePipeOtherList');
						return;
					}
					self.$message.error(resp.message)
					self.count = 0;
				});
			},

			operate(flag){
				if(!this.addForm.taskId ){
					this.$message.warning('请选择任务！');
					return;
				}
				if(!this.addForm.zjValue ){
					this.$message.warning('请输入直径！');
					return;
				}
				if(!this.addForm.cdValue ){
					this.$message.warning('请输入长度！');
					return;
				}
				if(!this.addForm.zlValue ){
					this.$message.warning('请输入产品重量！');
					return;
				}
				if(!this.addForm.qwValue ){
					this.$message.warning('请输入气味！');
					return;
				}
				if(!this.addForm.zzValue ){
					this.$message.warning('请输入杂质！');
					return;
				}
				if(!this.addForm.wgValue ){
					this.$message.warning('请输入外观！');
					return;
				}
				if(!this.addForm.phValue ){
					this.$message.warning('请输入壁厚！');
					return;
				}
				if(!this.addForm.jkValue ){
					this.$message.warning('请输入尖口！');
					return;
				}

				if(this.count == 0){
					let self = this;
					let params = Object.assign({},self.addForm);
					if(flag == 'start'){
						params.lineStatus = '1';
						params.zjUserName = getStore().userName;
					}
					self.$http({
						url: "/jinl/lineOther/updateLineOther",
						method: "post",
						params:params
					}).then(resp => {
						if (resp.success) {
							console.log(resp.result);
							self.$message.success('操作成功')
							self.$eventBus.$emit('updatePipeOtherList');
							return;
						}
						self.$message.error(resp.message);
						self.count = 0;
					});
				}
			},

			getUPlanManages() {
				let self = this;
				self.plans = [];
				let all = (self.addForm.lineStatus == '1' )?'1':'';
				let itemName = self.tabName.split("（")[0];
				self.$http({
					url: "/jinl/plan/getUPlanManages",
					method: "post",
					params:{all:all,itemName:itemName}
				}).then(resp => {
					if (resp.success) {
						console.log(resp.result);
						for(let data of resp.result){
							data.label = '['+data.planName+']    '+data.gradeValue;
						}
						self.plans = resp.result;
					}
				});
			},

		},

		watch: {
			editData(val) {
				console.log(val);
				this.user = getStore();
				this.count = 0;
				for (let key in  this.addForm) {
					this.addForm[key] = val[key] || ''
				}
				this.getUPlanManages();
				if(!this.addForm.id){
					this.addForm.createUserName = this.user.userName;
				}
				this.disabled = this.addForm.lineStatus == '1' ?true:false;
			},

		},

		mounted() {

		},
	}
</script>
<style lang="scss" scoped>
	@import "@/style/dialog.scss";

	.flex_ {
		width: 150px;

		._left {
			color: #9e9e9e;
		}
	}

	.nav_list {
		margin-top: 20px;

		._title {
			line-height: 40px;
			color: #00D1D0;
			display: flex;
			justify-content: space-between;

			i {
				font-size: 16px;
				margin-right: 5px;
			}
		}

		.edit_ {
			color: #409EFF;
			cursor: pointer;
		}
	}
</style>